<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitereview
 * @copyright  Copyright 2012-2013 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: create.tpl 6590 2013-04-01 00:00:00Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
 ?>

<?php
$this->headScript()
        ->appendFile($this->layout()->staticBaseUrl . 'externals/autocompleter/Observer.js')
        ->appendFile($this->layout()->staticBaseUrl . 'externals/autocompleter/Autocompleter.js')
        ->appendFile($this->layout()->staticBaseUrl . 'externals/autocompleter/Autocompleter.Local.js')
        ->appendFile($this->layout()->staticBaseUrl . 'externals/autocompleter/Autocompleter.Request.js');
?> 

<!--WE ARE NOT USING STATIC BASE URL BECAUSE SOCIAL ENGINE ALSO NOT USE FOR THIS JS-->
<!--CHECK HERE Engine_View_Helper_TinyMce => protected function _renderScript()-->
<?php $this->headScript()->appendFile($this->baseUrl().'/externals/tinymce/tiny_mce.js');?>

<script type="text/javascript">
  en4.core.runonce.add(function()
  {
    new Autocompleter.Request.JSON('tags', '<?php echo $this->url(array('module' => 'seaocore', 'controller' => 'index', 'action' => 'tag-suggest', 'resourceType' => 'sitereview_listing'), 'default', true) ?>', {
      'postVar' : 'text',
      'minLength': 1,
      'selectMode': 'pick',
      'autocompleteType': 'tag',
      'className': 'tag-autosuggest',
      'customChoices' : true,
      'filterSubset' : true,
      'multiple' : true,
      'injectChoice': function(token){
        var choice = new Element('li', {'class': 'autocompleter-choices', 'value':token.label, 'id':token.id});
        new Element('div', {'html': this.markQueryValue(token.label),'class': 'autocompleter-choice'}).inject(choice);
        choice.inputValue = token;
        this.addChoiceEvents(choice).inject(this.choices);
        choice.store('autocompleteChoice', token);
      }
    });
  });
  //<!--

	window.addEvent('domready', function() { 
		checkDraft();
	});

	function checkDraft(){
		if($('draft')){
			if($('draft').value==1) {
				$("search-wrapper").style.display="none";
				$("search").checked= false;
			} else{
				$("search-wrapper").style.display="block";
				$("search").checked= true;
			}
		}
	}

  en4.core.runonce.add(function(){
     if('<?php echo $this->expiry_setting; ?>' !=1){
       document.getElementById("end_date_enable-wrapper").style.display = "none";
     }
    if($('end_date-date')){
      // check end date and make it the same date if it's too
      cal_end_date.calendars[0].start = new Date( $('end_date-date').value );
      // redraw calendar
      cal_end_date.navigate(cal_end_date.calendars[0], 'm', 1);
      cal_end_date.navigate(cal_end_date.calendars[0], 'm', -1);
    }

  });
  var updateTextFields = function(endsettings)
  {
    var endtime_element = document.getElementById("end_date-wrapper");
    endtime_element.style.display = "none";

    if (endsettings.value == 0)
    {
      endtime_element.style.display = "none";
      return;
    }

    if (endsettings.value == 1)
    {
      endtime_element.style.display = "block";
      return;
    }
  }

  en4.core.runonce.add(updateTextFields);
</script>
<?php
/* Include the common user-end field switching javascript */
echo $this->partial('_jsSwitch.tpl', 'fields', array(
        //'topLevelId' => (int) @$this->topLevelId,
        //'topLevelValue' => (int) @$this->topLevelValue
))
?>

<?php if (empty($this->country)) include_once APPLICATION_PATH . '/application/modules/Sitereview/views/scripts/navigation_views.tpl'; ?>
<?php if ($this->category_count <= 0): ?>
    <div class="tip"> 
      <span>
				<?php if($this->level_id == 1): ?>
					<?php echo $this->translate("Note: Users will not be able to create listings in '%s', until you have created atleast one category. Please create some categories from the Admin Panel for this listing type to enable users to create listings.", $this->listing_plural_lc); ?>
				<?php else: ?>
					<?php echo $this->translate("Sorry, you can not post a new listing right now. Please try again after sometime or contact us by filling the 'Contact Us' form using the 'Contact' link available in the footer of our site."); ?>
				<?php endif; ?>	
      </span>
    </div>
<?php endif; ?>
<div class='layout_middle sr_create_list_form'>
  <?php if ($this->current_count >= $this->quota && !empty($this->quota)): ?>
    <div class="tip"> 
      <span>
        <?php echo $this->translate("You have already created the maximum number of $this->listing_singular_lc allowed."); ?>
      </span>
    </div>
    <br/>
  <?php elseif($this->category_count > 0): ?>
    <?php if ($this->sitereview_render == 'sitereview_form') {
      echo $this->form->setAttrib('class', 'global_form sr_create_list_form')->render($this);
    } else {
      echo $this->translate($this->sitereview_formrender);
    } ?>
  <?php endif; ?>
</div>

<script type="text/javascript">
  if($('subcategory_id'))
    $('subcategory_id').style.display = 'none';
</script>

<script type="text/javascript">

  var getProfileType = function(category_id) {
    var mapping = <?php echo Zend_Json_Encoder::encode(Engine_Api::_()->getDbTable('categories', 'sitereview')->getMapping($this->listingtype_id, 'profile_type')); ?>;
    for(i = 0; i < mapping.length; i++) {
      if(mapping[i].category_id == category_id)
        return mapping[i].profile_type;
    }
    return 0;
  }

  var defaultProfileId = '<?php echo '0_0_' . $this->defaultProfileId ?>'+'-wrapper';
  if($type($(defaultProfileId)) && typeof $(defaultProfileId) != 'undefined') {
    $(defaultProfileId).setStyle('display', 'none');
  }

	if($('overview-wrapper')) {
    var element_id = 'overview';
		tinyMCE.init({
		mode: "exact",
		elements : element_id,
		plugins: "preview,table,layer,style,xhtmlxtras,media,paste,spellchecker,iespell,fullscreen",
		theme: "advanced",
		theme_advanced_buttons1: "fullscreen,preview,code,|,cut,copy,paste,pastetext,pasteword,|,undo,redo,|, link,unlink,anchor,charmap,image,media,|,hr,removeformat,cleanup",
		theme_advanced_buttons2: "bold,italic,underline,strikethrough,|,bullist,numlist,|,outdent,indent,blockquote,|,justifyleft,justifycenter,justifyright,justifyfull,|,sub,sup,|,tablecontrols",
		theme_advanced_buttons3: "formatselect,fontselect,fontsizeselect,|,forecolor,backcolor,|,insertlayer,moveforward,movebackward,absolute,|,styleprops,attribs,|,cite,del,ins,",
		theme_advanced_toolbar_align: "left",
		theme_advanced_toolbar_location: "top",
		element_format: "html",
		height: "225px",
		convert_urls: false,
		media_strict: false,
		language: '<?php echo $this->language; ?>',
		directionality: '<?php echo $this->directionality; ?>',
		upload_url: '<?php echo $this->upload_url; ?>'
		});
	}
</script>

<?php
    if (!empty($this->country)):
?>
<style>
    .sr_create_list_form{
        background:#eaeaea ;
    }
    
    #sitereviews_create{
        width: 665px;
    }
    #smoothbox_window #global_page_sitereview-index-create #global_content_simple #sitereviews_create{
        height: 550px;
        overflow: auto;
    }
</style>
<?php endif;?>